//
//  TLNavigationController.m
//  Books
//
//  Created by tao故乡的云 on 2017/3/18.
//  Copyright © 2017年 故乡的云. All rights reserved.
//

#import "TLNavigationController.h"

@interface TLNavigationController ()

@end

@implementation TLNavigationController

+ (void)initialize {
    // 设置导航条背景图片，当导航栏用在TLNavigationController中, appearance设置才会生效
    UINavigationBar *bar = [UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[[self class]]];
    [bar setBackgroundImage:[UIImage imageNamed:@"navBg"] forBarMetrics:UIBarMetricsDefault];
//    bar.translucent = NO; // 毛玻璃效果
//    [bar setBackgroundColor:[UIColor brownColor]];
//    bar.barTintColor = [UIColor brownColor];
    
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.childViewControllers.count) {
        viewController.hidesBottomBarWhenPushed = YES;
        
        UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [backBtn setTitle:@"返回" forState:UIControlStateNormal];;
        [backBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [backBtn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
        [backBtn setImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:UIControlStateNormal];
        [backBtn setImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateHighlighted];
        backBtn.frame = CGRectMake(0, 0, 70, 35);
        //        backBtn.backgroundColor = [UIColor yellowColor];
        UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
        
        // btn 内容左对齐
        backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        // 设置左偏移
        backBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
        // 监听点击
        [backBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        
        viewController.navigationItem.leftBarButtonItem = backItem;

    }
    [super pushViewController:viewController animated:animated];
}

- (void)back {
    [self popViewControllerAnimated:YES];
}

@end
